package com.shilei.spring.util;

import com.shilei.spring.aop.aop.LogAutoAop;
import com.shilei.spring.aop.cglib.CglibFactory;
import com.shilei.spring.annotation.LogAuto;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 石雷
 * shilei1@jiayuan.com
 * 2021/8/31/031 17:27
 */
public class AopUtil {
    public static void initProxy(String pack){
        try {
            Set<Class> annotations = new HashSet<>();
            annotations.add(LogAuto.class);

            Set<Class<?>> classByAnnotation = AnnotationUtil.getClassByAnnotation(pack, annotations);
            for (Class<?> aClass : classByAnnotation) {
                Object o = new CglibFactory().myCglibCreator(aClass, new LogAutoAop());
                BeanUtil.setBean(aClass.getName(),o);
                System.out.println("代理类设置: "+aClass.getName()+" --> "+o.getClass().getName());
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}
